//
//  MHComicDetailViewController.m
//  ManHua
//
//  Created by 赵永泉 on 15/10/26.
//  Copyright © 2015年 蓝欧科技. All rights reserved.
//

#import "MHComicDetailViewController.h"
#import "MHEpisodeNumberCell.h"
#import "MHComicPictureViewController.h"
#import "MHComicCommentViewController.h"

@interface MHComicDetailViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UICollectionView *collectionView;



@end

@implementation MHComicDetailViewController


// 新添加一个评论的Btn
- (void)addCommentBtn
{
    
    UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc]initWithTitle:@"评论" style:(UIBarButtonItemStylePlain) target:self action:@selector(GotoCommentAction:)];
    self.navigationItem.rightBarButtonItem = rightBtn;
}

- (void)GotoCommentAction:(UIBarButtonItem *)rightBtn
{
    MHComicCommentViewController *commentVC = [[MHComicCommentViewController alloc]init];
    [self.navigationController pushViewController:commentVC animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor magentaColor];
    
    [self addCommentBtn];// 添加一个评论Btn
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    self.collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:flowLayout];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.collectionView registerNib:[UINib nibWithNibName:@"MHEpisodeNumberCell" bundle:nil] forCellWithReuseIdentifier:@"EpisodeNumber"];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 10;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MHEpisodeNumberCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"EpisodeNumber" forIndexPath:indexPath];
    cell.episodeNumber.text = [NSString stringWithFormat:@"%ld", indexPath.row];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    MHComicPictureViewController *comicPictureVC = [[MHComicPictureViewController alloc]init];
    [self.navigationController pushViewController:comicPictureVC animated:YES];
}

@end
